package com.luo.chengrui.module.sa.controller.admin.role;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.luo.chengrui.module.sa.controller.admin.role.vo.*;
import com.luo.chengrui.module.sa.dal.dataobject.role.RoleFolderModuleDO;
import com.luo.chengrui.module.sa.convert.role.RoleFolderModuleConvert;
import com.luo.chengrui.module.sa.service.role.RoleFolderModuleService;

@Tag(name = "管理后台 - 角色分类模块配置表")
@RestController
@RequestMapping("/sa/role-folder-module")
@Validated
public class RoleFolderModuleController {

    @Resource
    private RoleFolderModuleService roleFolderModuleService;

    @PostMapping("/create")
    @Operation(summary = "创建角色分类模块配置表")
    @PreAuthorize("@ss.hasPermission('sa:role-folder-module:config')")
    public CommonResult<String> createRoleFolderModule(@Valid @RequestBody RoleFolderModuleCreateReqVO createReqVO) {
        return success(roleFolderModuleService.createRoleFolderModule(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新角色分类模块配置表")
    @PreAuthorize("@ss.hasPermission('sa:role-folder-module:config')")
    public CommonResult<Boolean> updateRoleFolderModule(@Valid @RequestBody RoleFolderModuleUpdateReqVO updateReqVO) {
        roleFolderModuleService.updateRoleFolderModule(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得角色分类模块配置表")
    @Parameter(name = "roleFolderId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sa:role-folder-module:config')")
    public CommonResult<RoleFolderModuleRespVO> getByRoleFolderId(@RequestParam("roleFolderId") String roleFolderId) {
        RoleFolderModuleDO roleFolderModule = roleFolderModuleService.getByRoleFolderId(roleFolderId);
        return success(RoleFolderModuleConvert.INSTANCE.convert(roleFolderModule));
    }



}
